package org.goodprinciples.oracolo.dao.impl.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.goodprinciples.commons.command.CommandInfo;
import org.goodprinciples.oracolo.dao.impl.memento.ApplicationMemento;
import org.goodprinciples.oracolo.model.Application;
import org.goodprinciples.oracolo.model.Language;
import org.springframework.jdbc.core.RowMapper;

/**
 *
 * @author Francesco Conte
 */
public class ApplicationRowMapper implements RowMapper<Application> {

    @Override
    public Application mapRow(ResultSet rs, int i) throws SQLException {
        Application application = new Application();
        
        application.setId(rs.getLong(ApplicationMemento.ID.getColumn()));
        application.setName(rs.getString(ApplicationMemento.NAME.getColumn()));
        application.setDescription(rs.getString(ApplicationMemento.DESCRIPTION.getColumn()));
        
        Language defaultLanguage = new Language();
        defaultLanguage.setId(rs.getString(ApplicationMemento.DEFAULT_LANGUAGE.getColumn()));
        application.setDefaultLanguage(defaultLanguage);
        
        application.setReadVersion(rs.getLong(ApplicationMemento.VERSION.getColumn()));
        application.setVersion(application.getReadVersion());
        
        CommandInfo commandInfo = new CommandInfo();
        commandInfo.setUuid(rs.getString(ApplicationMemento.COMMAND_ID.getColumn()));
        application.setCommandInfo(commandInfo);
        
        return application;
    }
    
}
